export function flatten(arr) {
  const result = [];
  const obj = {};
  const List = [].concat(
    ...arr.map((item) => {
      if (item.children) {
        const arr = [].concat(item, ...this.flatten(item.children));
        delete item.children;
        return arr;
      }
      return [].concat(item);
    })
  );
  for (let i = 0; i < List.length; i++) {
    if (!obj[List[i].tagId]) {
      result.push(List[i]);
      obj[List[i].tagId] = true;
    }
  }

  return result;
}
